/*
Copyright (C) 2009  Raymond Jeon
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef __GL_LIB_DEFINE_H__
#define __GL_LIB_DEFINE_H__




#ifdef WIN32 
#include <windows.h>
#include <winsock2.h>
#include <mswsock.h>
#include <process.h>
#include <io.h>
#endif

#include <malloc.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <math.h>
#include <errno.h>


// Standard constants
#undef FALSE
#undef TRUE
#undef NULL
#undef _MAXPATH

#define FALSE		 0
#define TRUE		 1
#define NULL		 0
#define _MAXPATH	1024


#ifdef WIN32 
#define GlSocketGetLastError()			WSAGetLastError()
#define GlSocketSelect(a, b, c, d)		select(-1, a, b, c, d);
#define GlSocketClose(h)				closesocket(h)
#define sleep(a)						Sleep(1000*(a))

#else

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <malloc.h>
	#ifndef IRIX
		#include <unistd.h>
	#endif
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

typedef unsigned int SOCKET;
typedef void *GLTHREADRET;
typedef int HANDLE;


#define INVALID_SOCKET				(SOCKET)(~0)
#define SOCKET_ERROR				(-1)
#define GlSocketGetLastError()		(-1)
#define GlSocketSelect(a, b, c, d)	select(256, a, b, c, d)
#define GlSocketClose(h)			close(h)


#endif 



#ifndef WIN32
#define stricmp(s1, s2)				strcasecmp(s1, s2)
#define strnicmp(s1, s2, n)			strncasecmp(s1, s2, n)
#endif


#define __VAL(s)				((s) && *(s))
#define __SZ(s)					(__VAL(s) ? (s) : "")
#define __DEFAULT(s, d)			(__VAL(s) ? (s) : (d))
#define __MIN(a, b)				((a)<(b)?(a):(b))
#define __MAX(a, b)				((a)>(b)?(a):(b))
#define __RANGE(v, a, b)		((v)<(a)?(a):((v)>(b)?(b):(v)))



#define				__MAX__( x, y )						((x) > (y) ? (x) : (y))
#define				__MIN__( x, y )						((x) < (y) ? (x) : (y))


#endif	// __GL_LIB_DEFINE_H__



